package com.jiazhong.boot.redis.shuxin.test;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.List;

@SpringBootTest
@Slf4j
public class ListApp {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void a() {
        ListOperations<String, String> forList = stringRedisTemplate.opsForList();
        forList.leftPush("A", "aa");
        forList.leftPush("A", "bb");
        forList.leftPushAll("A", "aa", "cc", "dd", "ee");
        forList.rightPush("A", "11");
        forList.rightPushAll("A", "22", "33", "44", "55", "66");
        forList.leftPushIfPresent("A", "aa");
        forList.leftPushIfPresent("A", "kk");
        forList.rightPushIfPresent("A", "bb");
        forList.rightPushIfPresent("A", "mm");
    }

    @Test
    public void b() {
        ListOperations<String, String> forList = stringRedisTemplate.opsForList();
        List<String> list1 = forList.range("A", 0, -1);
        List<String> list2 = forList.range("A", 2, 6);
        log.info("list1:{}", list1);
        log.info("list2:{}", list2);
        String a4 = forList.index("A", 3);
        log.info("a4:{}", a4);
    }

    @Test
    public void c() {
        ListOperations<String, String> forList = stringRedisTemplate.opsForList();
        List<String> list1 = forList.range("A", 0, -1);
        log.info("list1:{}", list1);
        Long index1 = forList.indexOf("A", "bb");
        log.info("index1:{}", index1);
        Long index2 = forList.lastIndexOf("A", "bb");
        log.info("index2:{}", index2);
        Long size = forList.size("A");
        log.info("size:{}", size);
        forList.remove("A", 3, "kk");

        List<String> list2 = forList.range("A", 0, -1);
        log.info("list2:{}", list2);
        forList.leftPop("A");
        forList.leftPop("A", 2);
        List<String> list3 = forList.range("A", 0, -1);
        log.info("list3:{}", list3);
        forList.rightPop("A");
        forList.rightPop("A", 2);
        List<String> list4 = forList.range("A", 0, -1);
        log.info("list4:{}", list4);
    }
}
